package com.katze.boot.applet.ssh;

import com.katze.boot.applet.ssh.entity.SecureSSHProcessEntity;
import com.katze.boot.common.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;

public enum CommandType {

    STARTUP() {
        @Override
        public String command(SecureSSHProcessEntity entity) {
            if (StringUtils.isBlank(entity.getStartup())) {
                throw new BusinessException("尚未配置启动命令");
            }
            return "source /etc/profile;source ~/.bash_profile;source ~/.bashrc; cd " + entity.getPosition() + " && " + entity.getStartup();
        }
    },

    SHUTDOWN() {
        @Override
        public String command(SecureSSHProcessEntity entity) {
            if (StringUtils.isBlank(entity.getShutdown())) {
                throw new BusinessException("尚未配置关闭命令");
            }
            return "source /etc/profile;source ~/.bash_profile;source ~/.bashrc; cd " + entity.getPosition() + " && " + entity.getShutdown();
        }
    },
    STATUS() {
        @Override
        public String command(SecureSSHProcessEntity entity) {
            return "ps -ef|grep ".concat(entity.getName() + " |grep -v 'grep' |grep -v 'bash -c'");
        }
    };

    public abstract String command(SecureSSHProcessEntity entity);
}
